using System;
using System.Collections.Generic;
using System.Diagnostics;

[System.Serializable]
public class GuestStage
{
    public List<int> initEmotion;
    public List<int> targetEmotion;
    public int emotionChangeTurns;
    public float scoreMultiplierBouns;
}

[Serializable]
public class GuestData
{
    public int id;
    public string name;
    public List<int> currentEmotion;    //存储两个轴实时数据
    public List<GuestStage> stages;
    public string path;
    public string infoPath;     //病例介绍path

    //public List<String> guestDialog;
}

[Serializable]
public class GuestList { public List<GuestData> guests; }


public class Guest
{
    public int id;
    public string name;
    public List<int> currentEmotion;
    public List<GuestStage> stages;
    public string path;
    public string infoPath;
    //public List<String> guestDialog;

    private int curEmotionTurnCounter = 1;    // 当前回合数计数器（可选，运行时逻辑用）
    
    public Guest(GuestData data)
    {
        id = data.id;
        name = data.name;
        currentEmotion = new List<int>(data.currentEmotion);
        stages = data.stages;
        path = data.path;
        infoPath = data.infoPath;
        //guestDialog = data.guestDialog;
    }


    /// <summary>
    /// 自增该角色当前回合次数
    /// </summary>
    /// <param name="isReset">是否重置</param>
    /// <returns></returns>
    public int SetGuestTurn(bool isReset = false)
    {
        if (isReset)
        {
            curEmotionTurnCounter = 1;
            return 1;
        }
        return curEmotionTurnCounter++;
    }

    /// <summary>
    /// 获得当前角色所处回合次数
    /// </summary>
    /// <returns></returns>
    public int GetCurrentGuestTurn()
    {
        return curEmotionTurnCounter;
    }


    /// <summary>
    /// 返回该阶段角色应该有的最大阶段数
    /// </summary>
    /// <param name="curState"></param>
    /// <returns></returns>
    public int GetCurStateMaxTurn(GameState curState)
    {
        if (curState == GameState.FirstTurn)
        {
            return stages[0].emotionChangeTurns;
        }
        else if (curState == GameState.SecondTurn)
        {
            return stages[1].emotionChangeTurns;
        }
        return 0;
    }


    ///<summary>
    /// 分别获得角色emo两个轴数据
    /// </summary>
    /// <param name="isPowerBar">是否返回能量轴</param>
    /// <returns></returns>
    public int GetBarData(bool isPowerBar)
    {
        if (!isPowerBar) return currentEmotion[0];
        else return currentEmotion[1];
    }


    /// <summary>
    /// 情绪轴计算
    /// </summary>
    /// <param name="update"></param>
    /// <param name="isPunish"></param>
    public void UpdateEmotion(List<int> update, GameState curState)
    {
        float totalEffect = 1;
        switch (curState)
        {
            case GameState.FirstTurn:
                totalEffect = 1 - stages[0].scoreMultiplierBouns * (curEmotionTurnCounter - 2);
                break;
            case GameState.SecondTurn:
                totalEffect = 1 - stages[1].scoreMultiplierBouns * (curEmotionTurnCounter - 2);
                break;
        }

        for (int i = 0; i < update.Count; i++)
        {
            currentEmotion[i] += (int)(update[i] * totalEffect);
            GameManager.Instance.DebugToNet($"原效果为：{update[i]}，减免数值为：{totalEffect}，造成效果为：{update[i] * totalEffect}");
        }

        if (CompareEmotion(curState))
        {
            Debug.WriteLine("满足条件");
            //TODO: 
        }

        //GamePanel.Instance.UpdateGuestUI(this);
    }


    /// <summary>
    /// 对比是否达标
    /// </summary>
    /// <param name="curState"></param>
    /// <returns></returns>
    public bool CompareEmotion(GameState curState)
    {
        List<int> targetEmotion = new();

        switch (curState)
        {
            case GameState.FirstTurn:
                targetEmotion = stages[0].targetEmotion;
                break;
            case GameState.SecondTurn:
                targetEmotion = stages[1].targetEmotion;
                break;

            default:
                targetEmotion = stages[0].targetEmotion;
                break;
        }

        for (int i = 0; i < currentEmotion.Count; i++)
        {
            if (currentEmotion[i] < targetEmotion[i]) return false;
        }
        return true;
    }


    //targetEmotion = new List<int>(data.targetEmotion);
}

